/**
 * 审查记录 管理模块
 */

const router = require('koa-router')()
const ReviewRecord = require('./../models/reviewRecordsSchema')
const util = require('./../utils/util')

router.prefix('/reviewRecord')

// 获取reviewRecord 列表
router.get('/list', async (ctx) => {
    const { rbId, reviewFraud, reviewUserName } = ctx.request.query;
    const { page, skipIndex } = util.pager(ctx.request.query);
    let params = {}
    if (rbId) params.rbId = rbId;
    if (reviewFraud && reviewFraud != 3 ) params.reviewFraud = reviewFraud;
    if (reviewUserName) params.reviewUserName = reviewUserName;

    try {
        // 根据条件查询所有 reviewRecord 列表
        const query = ReviewRecord.find(params, { _id: 0 })
        const list = await query.skip(skipIndex).limit(page.pageSize)
        const total = await ReviewRecord.countDocuments(params)

        ctx.body = util.success({
            page: {
                ...page,
                total
            },
            list
        })

    } catch (error) {
        ctx.body = util.fail(`查询异常:${error.stack}`)
    }
})


module.exports = router    